package com.example.Opd_ISF_Android_Application.view.adapters;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.example.Opd_ISF_Android_Application.R;
import com.example.Opd_ISF_Android_Application.model.Ranking;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Dell
 * Date: 27/03/13
 * Time: 20:59
 * To change this template use File | Settings | File Templates.
 */
public class RankingAdapter extends ArrayAdapter<Ranking> {
    private Context context;
    private int layoutResourceId;
    private Ranking data[] = null;

    public RankingAdapter(Context context, int layoutResourceId, Ranking[] data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public Ranking getItem(int position) {
        return super.getItem(position);    //To change body of overridden methods use File | Settings | File Templates.
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        RankingHolder holder = null;


        // Overlay (inflate) current element theme/content with custom
        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);


        holder = new RankingHolder();
        holder.tvName = (TextView) row.findViewById(R.id.tvRankingName);
        holder.tvCountry = (TextView) row.findViewById(R.id.tvRankingCountry);
        holder.tvRegion = (TextView) row.findViewById(R.id.tvRankingRegion);
        holder.tvScore = (TextView) row.findViewById(R.id.tvRankingScore);

        row.setTag(holder);
        Ranking ranking = data[position];
        holder.tvName.setText(ranking.getName());
        holder.tvCountry.setText(ranking.getCountry());
        holder.tvRegion.setText(ranking.getRegion());
        holder.tvScore.setText(ranking.getScore());

        return row;
    }


    // hold elements for a list item
    static class RankingHolder {
        TextView tvName;
        TextView tvCountry;
        TextView tvRegion;
        TextView tvScore;
    }
}
